package com.os.opencv.java.chapter6;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Filter2D {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //读取图像并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/Pictures/111.jpg");
        HighGui.imshow("src", src);
        HighGui.waitKey(0);

        //用于均值滤波的卷积核
        Mat k1 = new Mat(3,3, CvType.CV_64F);
        double[] data3 = new double[]{
                0.111,0.111,0.111,0.111,
                0.111,0.111,0.111,0.111,
                0.111
        };
        k1.put(0,0,data3);

        //均值滤波并在屏幕上显示
        Mat dst = new Mat();
        Imgproc.filter2D(src, dst, -1, k1);
        HighGui.imshow("blur", dst);
        HighGui.waitKey(0);

        //用于锐化的卷积核
        Mat k2 = new Mat(3,3,CvType.CV_64F);
        double[] data = new double[]{
                0,-1,0,-1,5,-1
        };
        k2.put(0,0,data);

        //锐化操作并在屏幕上显示
        Imgproc.filter2D(src, dst, -1, k2);
        HighGui.imshow("sharpen1", dst);
        HighGui.waitKey(0);

        //调整过的锐化卷积核
        Mat k3 = new Mat(3,3,CvType.CV_64F);
        double[] data2 = new double[]{
                0,-0.5,0,-0.5,
                2.5,-0.5
        };
        k3.put(0,0,data2);

        //用调整过的锐化卷积核进行锐化并在屏幕上显示
        Imgproc.filter2D(src,dst,-1,k3);
        HighGui.imshow("sharpen2", dst);
        HighGui.waitKey(0);
        System.exit(0);
    }
}
